﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;

using System.Web;
using FirebirdSql.Data.FirebirdClient;
using NetDon.Variation.Data.DaoClasses;

namespace NetDon.OA.Portal.Product
{
    public class ProductXiaoSoftService
    {
        const string CommandText = "select C_STOCK.QUANTITY ,A_GOODS.SPEC,A_GOODS.GOODSNAME from A_GOODS inner join C_STOCK ON A_GOODS.GOODSID =C_STOCK.GOODSID WHERE A_GOODS.GOODSCODE=@GOODSCODE";

        public static dynamic GetProductInfo(string sku)
        {
            dynamic productInfo = new
                                      {
                                          SubSKU =sku,
                                          StockQuantity =string.Empty,
                                          Spec =string.Empty,
                                          ProductName =string.Empty
                                      };
            // do it yourself, and use your project's connection string
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["XiaoSoft"].ConnectionString;
            using (var conn = new FbConnection(connectionString))
            {
                conn.Open();
                FbCommand cmd = new FbCommand(CommandText, conn);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("@GOODSCODE", FbDbType.VarChar).Value = sku;
                var reader = cmd.ExecuteReader(CommandBehavior.Default);
                if (reader.Read())
                {
                    productInfo = new
                    {
                        SubSKU = sku,
                        StockQuantity = reader.GetInt32(0).ToString(),
                        Spec =reader.GetString(1),
                        ProductName = reader.GetString(2),
                    };
                }
                reader.Close();
            }

            return productInfo;
        }

        
    }
}